﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EasyUI.Master" AutoEventWireup="true" CodeBehind="ListR.aspx.cs" Inherits="jnxc.Web.nurseryRecord.ListR" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script type="text/javascript">
        $(function () {
            InitGird();
        });
        function getArgs() {
            var args = {};
            var match = null;
            var search = decodeURIComponent(location.search.substring(1));           
            return search;
        }
        function outword() {
            DownLoad(getArgs());
        }
        function DownLoad(args) {
            var form = $("<form>");   //定义一个form表单
            form.attr('style', 'display:none');   //在form表单中添加查询参数
            form.attr('target', '');
            form.attr('method', 'post');
            form.attr('action', "GetNursery.ashx?action=tt&" + args);

            $('body').append(form);  //将表单放置在web中 
            //form.append(input1);   //将查询参数控件提交到表单上
            form.submit();

        }

        //初始化表格
        function InitGird() {
            var args = getArgs();
            $('#tt').datagrid({
                title: '苗圃（花圃）有害生物调查记录表', //表格标题
                url: 'GetNursery.ashx?' + args, //请求数据的页面
                sortName: 'nurseryId', //排序字段
                idField: 'nurseryId', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                singleSelect: true,
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                method: 'post',
                frozenColumns: [[
                    { field: 'ckb', checkbox: true },
                    {
                        title: '县', field: 'coname', width: 100, formatter: function (value, row) {
                            return row.coname + '(' + row.cobh + ')';
                        }
                    },
                    {
                        title: '乡镇', field: 'tname', width: 100, formatter: function (value, row) {
                            return row.tname + '(' + row.tbh + ')';
                        }
                    },
                    { title: '经度', width: 80, field: 'jd' },
                    { title: '纬度', width: 80, field: 'wd' },
                    { title: '海拨', width: 80, field: 'hb' },
                    { title: '场地名称', width: 80, field: 'nurseryName' },
                    { title: '面积（亩）', width: 80, field: 'totalArea' },
                    { title: '抽样面积（亩）', width: 80, field: 'sampleArea' },
                    { title: '上传时间', width: 120, field: 'investigationTime' }
                ]],

                columns: [
                    [
                     { title: '有害生物', width: 80, field: 'hname' },
                     { title: '寄主植物', width: 80, field: 'plantname' },
                     { title: '危害部位', width: 80, field: 'harmParts' },
                     { title: '被害株率', width: 80, field: 'nuseryHarm' },
                    {
                        title: '发生（危害）程度', width: 160, field: 'damageLevel', formatter: function (value, row, index) {
                            if (value == '轻度以下') {
                                return '<span class="dl1">轻度以下</span>';
                            }
                            else if (value == '轻度') {
                                return '<span class="dl2">轻度</span>';
                            }
                            else if (value == '中度') {
                                return '<span class="dl3">中度</span>';
                            }
                            else if (value == '重度') {
                                return '<span class="dl4">重度</span>';
                            }
                        }

                    },
                    {
                        title: '是否成灾', field: 'isDisaster', formatter: function (value, row, index) {
                            if (value == true) {
                                return '是';
                            }
                            else {
                                return '否';
                            }
                        }
                    },
                    { title: '备注', field: 'nurseryRemark' }
                    ]
                ],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号

            });


        }
        function removeUser() {

            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetNursery.ashx?nurseryId=' + row.nurseryId + "&action=delete",
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    $('#tt').datagrid('reload');
                                }
                                else {
                                    $.messager.alert("提示", "删除失败，请重新操作！", "info");
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }
    </script>
    <style>
        .fitem {
            float: left;
        }

            .fitem label {
                width: 30px;
                line-height: 24px;
            }

        .dl1 {
            color: green;
            font-weight: bold;
        }

        .dl2 {
            color: blue;
            font-weight: bold;
        }

        .dl3 {
            color: yellow;
            font-weight: bold;
        }

        .dl4 {
            color: red;
            font-weight: bold;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>
                <td style="padding-left: 2px">

                    <div style="padding: 2px;">
                        <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>                                     
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="outword()">导出</a>

                    </div>
                </td>
            </tr>
        </table>
    </div>
    <form id="fm" method="post"></form>
</asp:Content>


